<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>导航栏示例</title>
  <!-- 引入elementUI的css文件 -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<body>
<!-- 这里展示的是一个Vue实例的模板，稍后在JavaScript部分会定义 -->
<div id="app">
  <el-container>
    <el-aside width="200px">
      <!-- 左边的侧导航栏 -->
      <el-menu :default-openeds="defaultOpeneds" class="el-menu-vertical-demo" background-color="#333" text-color="#fff" active-text-color="#ff0">
        <el-submenu v-for="(item, index) in navData" :key="index" :index="item.path">
          <template slot="title">
            <i class="el-icon-location"></i>
            <span>{{ item.title }}</span>
          </template>
          <el-menu-item v-for="(subItem, subIndex) in item.submenus" :key="subIndex" :index="`${item.path}-${subIndex}`" @click="handleMenuClick(subItem.path)">{{ subItem.title }}</el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-main>
        <!-- 右边的主内容区 -->
        <iframe :src="pageUrl"></iframe>
      </el-main>
    </el-container>
  </el-container>
</div>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<!-- 引入自己编写的JavaScript文件 -->
<script src="index.js"></script>
</body>
<script>
  // 定义Vue实例
  let app = new Vue({
    el: "#app",
    data: {
      navData: [    // 导航栏数据
        {
          path: "/page1",
          title: "页面一",
          submenus: [
            {
              title: "页面一-1",
              path: "page1-login"
            },
            {
              title: "页面一-2",
              path: "page1-2.html"
            }
          ]
        },
        {
          path: "/page2",
          title: "页面二",
          submenus: [
            {
              title: "页面二-1",
              path: "page2-1.html"
            },
            {
              title: "页面二-2",
              path: "page2-2.html"
            }
          ]
        },
        {
          path: "/page3",
          title: "页面三",
          submenus: [
            {
              title: "页面三-1",
              path: "page3-1.html"
            },
            {
              title: "页面三-2",
              path: "page3-2.html"
            }
          ]
        }
      ],
      defaultOpeneds: ["/page1"],  // 默认展开的导航栏
      pageUrl: ""                  // 右侧显示的页面链接
    },
    methods: {
      handleMenuClick(path) {      // 处理导航栏点击事件
        let [, ...paths] = path.split("-");
        this.pageUrl = paths.join("/") + ".html";
      }
    }
  });
</script>
</html>